<template>
  <el-dialog v-model="centerDialogVisible" :show-close="false" top="2.3%" class="TerouroDialog" width="600px" center>
    <div class="closerank" @click="close">
      <strong></strong>
      <h3>{{ $t("language.Terouro.name") }}</h3>
      <span>
        <el-icon color="#b5b6c8" size="16">
          <Close />
        </el-icon>
      </span>
    </div>
    <div id="Terouro">
      <main>
        <Skeleton :loading="loading">
          <template #ske>
            <div style="
                width: 100%;
                height: 100%;
                display: flex;
                flex-direction: column;
                justify-content: flex-start;
                align-items: center;
              ">
              <el-skeleton-item variant="image" style="width: 100%; height: 180px" />
              <div style="width: 100%; display: flex; margin-top: 20px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="width: 100%; display: flex; margin-top: 10px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="width: 100%; display: flex; margin-top: 10px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="width: 100%; display: flex; margin-top: 20px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="width: 100%; display: flex; margin-top: 10px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="width: 100%; display: flex; margin-top: 10px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  margin-top: 50px;
                ">
                <el-skeleton-item variant="image" style="width: 43px; height: 43px" />
                <el-skeleton-item variant="image" style="width: 43px; height: 43px; margin-left: 30px" />
                <el-skeleton-item variant="image" style="width: 43px; height: 43px; margin-left: 30px" />
                <el-skeleton-item variant="image" style="width: 43px; height: 43px; margin-left: 30px" />
              </div>
              <div style="
                  width: 100%;
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  margin-top: 20px;
                ">
                <el-skeleton-item variant="h3" style="width: 50%; height: 20px" />
              </div>
              <el-skeleton-item variant="text" style="width: 100%; height: 40px; margin-top: 20px" />

              <el-skeleton-item variant="text" style="width: 100%; height: 40px; margin-top: 20px" />
            </div>
          </template>
          <template #main>
            <NuxtImg src="/img/banner1.png" alt="" />
            <ul v-if="shareinfo.yesterdayData.registerCount != null">
              <li>
                <span>{{ $t('language.Terouro.yesterday.Registr') }}</span>
                <span>{{ shareinfo.yesterdayData.registerCount }}</span>
              </li>
              <li>
                <span>{{ $t('language.Terouro.yesterday.level') }}</span>
                <span>{{ shareinfo.yesterdayData.firstRechargeCount }}</span>
              </li>
              <li>
                <span>{{ $t('language.Terouro.yesterday.record') }}</span>
                <span>{{ shareinfo.yesterdayData.bonus }}</span>
              </li>
            </ul>
            <ul>
              <li>
                <span>{{ $t('language.Terouro.today.Registr') }}</span>
                <span>{{ shareinfo.todayData.registerCount }}</span>
              </li>
              <li>
                <span>{{ $t('language.Terouro.today.level') }}</span>
                <span>{{ shareinfo.todayData.firstRechargeCount }}</span>
              </li>
              <li>
                <span>{{ $t('language.Terouro.today.record') }}</span>
                <span>{{ shareinfo.todayData.bonus }}</span>
              </li>
            </ul>
            <div class="img">
              <NuxtImg v-for="(item, index) in imglist" @click="item.callback" :key="index" :src="item.img" alt="" />
            </div>
            <h3>{{ $t('language.Terouro.title') }}</h3>
            <dl>
              <dd>
                <span>{{ $t('language.Terouro.link1') }}</span>
                <div>
                  <span>{{ ip }}</span>
                  <el-button class="confirm" @click="copyToClipboard(ip)">{{
    $t("language.info.copy")
  }}</el-button>
                </div>
              </dd>
              <!-- v-if="Invite.code != ''" -->
              <dd v-if="Invite.code != ''">
                <span>{{ $t('language.Terouro.link2') }}</span>
                <div>
                  <span>{{ Invite.code }}</span>
                  <el-button class="confirm" @click="copyToClipboard(Invite.code)">{{ $t("language.info.copy")
                    }}</el-button>
                </div>
              </dd>
            </dl>
          </template>
        </Skeleton>
      </main>
    </div>
  </el-dialog>
</template>
<script setup lang="ts">
import { reactive, ref, nextTick, onBeforeMount, watch,shallowRef, computed} from "vue";
import { useI18n } from "vue-i18n";
import { Close } from '@element-plus/icons-vue'
// import { copyToClipboard } from "../utils/common";
// import store from "@/store";
const { t } = useI18n();
let centerDialogVisible = computed(()=>store.terouro);
let loading = shallowRef<boolean>(false);
const store = useStore()
let userinfo = computed(():any => store.userinfo)
let shareinfo: any = reactive({
  todayData: { registerCount: 0, firstRechargeCount: 0, bonus: 0 },
  yesterdayData: { registerCount: 0, firstRechargeCount: 0, bonus: 0 }
})
// 复制
let copyToClipboard = (text: string | number | null | undefined) => {
  let tmpTextField: any = document.createElement("textarea");
  tmpTextField.textContent = text;
  tmpTextField.setAttribute("style", "position:absolute; right:200%;");
  document.body.appendChild(tmpTextField);
  tmpTextField.select();
  tmpTextField.setSelectionRange(0, 99999); /*For mobile devices*/
  document.execCommand("copy");
  ElMessage({
    message: t("language.commontips.copysuccess"),
    type: "success",
    duration: 1000,
  });
}
let Invite: any = reactive<{code:string,registerCount:number}>({
  code: "",
  registerCount: 0
})
// 获取ip地址
let ip = shallowRef<null|string|undefined>(null)
onBeforeMount(() => {
  ip.value = window.location.href
})
//数据初始化
let initData = async () => {
  // 获取推广信息
  loading.value = true
  await nextTick()
  await Promise.all([useHttpPOST("/Activity/v1.0/InviteData", { id: userinfo.value.gameID }), useHttpPOST(`/Activity/v1.0/Invite/Code`, { id: userinfo.value.gameID })]).then((res: any) => {
    for (let key in res[0].data.value.data) {
      shareinfo[key] = res[0].data.value.data[key]
    }
    for (let key in res[1].data.value.data) {
      Invite[key] = res[1].data.value.data[key]
    }
  }).finally(() => {
    loading.value = false
  })
}

watch(centerDialogVisible, (newval) => {
  if (newval) {

    nextTick(() => {
      initData()
      loading.value = false;
      // let time = setInterval(() => {
      //   // loading.value = false;
      //   clearInterval(time);
      // }, 500);
    });
  }
}, {
  immediate: true
});

let opent = () => {
  store.$patch({terouro:true})
  // centerDialogVisible.value = true;
};

const open2 = () => {
  ElMessage({
    message: t("language.info.copytips"),
    type: "success",
  });
};
let close = () => {
  // centerDialogVisible.value = false;
  store.$patch({terouro:false})
};
// const getImg = (url) => {
//   return new URL(`../assets/img/${url}`, import.meta.url).href;
// };
let imglist = reactive<{img:string,callback:Function}[]>([
  {
    img: "/img/fly.png",
    callback: () => { window.open('https://t.me/share/url?url=https://bc.wg141.com/home?uid=19676882%26t=1714100324096&text=Crypto Casino | Bitcoin Gambling |Sports Betting Join our-Leading Crypto Casino.Best crypto gambling with 5000+Slots, Dice, Roulette, Blackjack %26 Sports Betting.Enjoy instant withdrawals in BRL') }
  },
  {
    img: "/img/re9.png",
    callback: () => { window.open('https://m.facebook.com/') }
  },
  {
    img: "/img/re8.png",
    callback: () => { window.open('https://api.whatsapp.com/send/?text=Crypto Casino | Bitcoin Gambling |Sports Betting Join our-Leading Crypto Casino.Best crypto gambling with 5000+Slots, Dice, Roulette, Blackjack %26 Sports Betting.Enjoy instant withdrawals in BRL&url=https://bc.wg141.com/home?uid=19676882%26t=1714100324096') }
  },
  {
    img: "/img/re10.png",
    callback: () => { window.open('https://www.instagram.com/') }
  },
  {
    img: "/img/re7.png",
    callback: () => { window.open('https://twitter.com/intent/post?text=Crypto Casino | Bitcoin Gambling |Sports Betting Join our-Leading Crypto Casino.Best crypto gambling with 5000+Slots, Dice, Roulette, Blackjack %26 Sports Betting.Enjoy instant withdrawals in BRL&url=https://bc.wg141.com/home?uid=19676882%26t=1714100324096') }
  },

]);
defineExpose({
  opent,
});
</script>
<style lang="scss">
.dropdown .el-scrollbar__wrap {
  width: 250px !important;
  border: none !important;
}

.dropdown .el-popper {
  border: none !important;
}

.dropdown .el-dropdown__list {
  box-shadow: none !important;
  border: none !important;
}

.dropdown .el-scrollbar__view {
  box-shadow: none !important;
  border: none !important;
}

.dropdown .el-scrollbar {
  box-shadow: none !important;
  border: none !important;
}

.el-scrollbar__view .dropdown .el-scrollbar,
.dropdown .el-scrollbar__view,
.dropdown .el-dropdown__list,
.dropdown .el-dropdown__list,
.dropdown .el-popper__arrow::before,
.dropdown .el-popper {
  background-color: rgb(50, 53, 62) !important;
  box-shadow: none !important;
  border: none !important;
  border-radius: 4px !important;
  outline: none !important;
}

.el-dropdown-menu,
.dropdown {
  background-color: rgb(50, 53, 62) !important;
  box-shadow: none !important;
}



.tipsdropdown {
  font-size: 14px !important;
  color: #b5bac8 !important;
  height: 36px;
  padding: 0px 20px !important;
  display: flex !important;
  justify-content: flex-start !important;
  align-items: center !important;
  opacity: 1;
  transition: all 0.3s;

  span {
    display: block;
    margin-right: 5px;
    color: #fff
  }
}

.opcity {
  opacity: 0;
}

.dropdown .el-dropdown-menu__item {
  border-bottom: 1px solid #4a4c53 !important;
  padding: 8px 20px !important;
}

.dropdown .el-dropdown-menu__item:nth-child(3) {
  border: none;
}

.itemdropdown {
  width: 100% !important;
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;

  img {
    width: 16px !important;
    margin-right: 5px;
  }

  strong {
    font-size: 16px;
    font-weight: normal;
    color: #b5bac8;
    display: block;
    flex: 1;

  }

  >div {
    display: block !important;
    width: 60%;
    text-align: right !important;
    color: #b5bac8;
  }
}

.activedown {
  strong {
    color: #fff !important;
  }

  >div {
    color: #fff !important;
  }
}
</style>
<style lang="scss">
.TerouroDialog {
  padding: 10px !important;
  background-color: #32353e !important;
  border-radius: 10px;
  height: 90%;
  overflow-y: auto;
  --el-dialog-bg-color: #32353e !important;

  &::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
  }
}


.el-pager li {
  background-color: rgb(26, 26, 26) !important;

}

.el-pagination button {
  background: rgb(26, 26, 26) !important;
}

.el-dialog__header {
  padding: 0 0 0 !important;
}

.closerank {
  width: 100%;
  @include flex(row, space-between, center);
  border-bottom: 1px solid #4a4c53;
  padding-bottom: 15px;

  strong {
    width: 30px;
    display: block;
  }

  h3 {
    font-size: 18px;
    color: #b5b6c8;
    text-align: center;
    flex: 1;
  }

  span {
    display: block;
    width: 28px;
    height: 28px;
    @include flex(row, center, center);
    border: 2px solid #b5b6c8;
    border-radius: 16px;
    cursor: pointer;
  }
}

#Terouro {
  width: 100%;
  height: 100%;
  background: #32353e;
  padding: 0 10px;

  .van-skeleton-image,
  .van-skeleton-paragraph,
  .van-skeleton-title,
  .van-skeleton-avatar {
    background-color: rgb(61, 65, 72) !important;
    margin: 0;
    padding: 0;
  }

  main {
    width: 100%;
    margin-top: 20px;
    padding-bottom: 60px;

    >img {
      width: 100%;
      height: 170px;
    }

    ul {
      width: 100%;
      border: 1px solid #4a4c53;
      margin-top: 20px;

      li {
        @include flex(row, space-between, center);

        span {
          font-size: 14px;
          color: #b5bac8;
          text-align: center;
          display: block;
          padding: 10px 8px;
          width: 80%;
          border-right: 1px solid #4a4c53;
        }

        span+span {
          border: none;
          flex: 1;
        }
      }

      li+li {
        border-top: 1px solid #4a4c53;
      }
    }

    .img {
      width: 100%;
      padding: 40px 10px;
      @include flex(row, center, center);

      img {
        width: 43px;
        border-radius: 5px;
        cursor: pointer;
      }

      img+img {
        margin-left: 30px;
      }
    }

    h3 {
      text-align: center;
      color: #b5bac8;
      font-size: 18px;
    }

    >dl {
      width: 100%;
      margin-top: 30px;

      dd {
        width: 100%;
        @include flex(row, space-between, center);

        span {
          display: block;
          flex: 1;
          font-size: 14px;
          color: #b5bac8;
          text-align: center;
          word-wrap: break-word;
          margin-right: 10px;
        }

        >div {
          width: 70%;
          height: 50px;
          border: 1px solid #4c4c4f;
          border-radius: 7px;
          @include flex(row, space-between, center);
          padding: 10px 20px;

          span {
            flex: 1;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            font-size: 14px;
            color: #b5bac8;
            text-align: left;
          }

          >.confirm {
            font-style: normal;
            background-color: #0a906c;
            color: #fff;
            border-radius: 5px;

            height: 28px;
            padding: 10px;
            border: none;
            font-size: 12px;
          }
        }
      }

      dd+dd {
        margin-top: 20px;
      }
    }
  }
}
</style>
